import common.CommonFunction;
import common.Mask;

import employeeRecord.editEmp;

import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileReference;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.DateField;
import mx.events.CloseEvent;
import mx.events.ListEvent;
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

[Embed(source="/images/success.png")]private var successIcon:Class;
[Embed(source="/images/error.png")]private var errorIcon:Class;
[Embed(source="/images/question.png")]private var questionIcon:Class;

public var infoObject:Object;

public function onCreationComplete():void
{
	infoObject = new Object();
	infoObject["date"] = new Date();
	getEmployeeDetail.send(infoObject);
	Mask.show(CommonFunction.getMessages('pleaseWait'));
}

public var customerXML:XML;
public var customerList:ArrayCollection;
public function onSuccess(event:ResultEvent):void
{
	Mask.close();
	customerXML = event.result as XML;
	
	customerList = new ArrayCollection();
	for each(var obj:Object in customerXML.record)
	{
		customerList.addItem({select:false, col0:obj.empID, 
			col1:obj.empName, col2:obj.empStatus, col3:obj.email, col4:obj.description, col5:obj.dob, col6:obj.address,
			col7:obj.city, col8:obj.state, col9:obj.country, col10:obj.imgPath, col11:obj.phNumber, col12:obj.area});
	}
	customerDetailsGrid.dataProvider = customerList;
}

public function onFailure(event:FaultEvent):void
{
	Mask.close();
	Alert.show(event.message + "");
}
public var custL:ArrayCollection;
public var empl:editEmp;
protected function edit_clickHandle():void
{
	custL = new ArrayCollection();
	empl = editEmp(PopUpManager.createPopUp(this, editEmp, true));
	for each(var obj:Object in customerDetailsGrid.dataProvider)
	{
		if(obj.select == true)
		{
			custL.addItem({select:false, col0:obj.col0, 
				col1:obj.col1, col2:obj.col2, col3:obj.col3, col4:obj.col4, col5:obj.col5, col6:obj.col6,
				col7:obj.col7, col8:obj.col8, col9:obj.col9, col10:obj.col10, col11:obj.col11, col12:obj.col12});
		}
	}
	empl.empID.text = custL.getItemAt(0).col0;
	empl.empName.text = custL.getItemAt(0).col1;
	empl.dob.data = DateField.stringToDate(custL.getItemAt(0).col5, "YYYY/MM/DD");
	empl.add.text = custL.getItemAt(0).col6;
	empl.country.selectedItem = custL.getItemAt(0).col9;
	empl.stateSel = custL.getItemAt(0).col8;
	empl.citySel = custL.getItemAt(0).col7;
	empl.areaSel = custL.getItemAt(0).col12;
	empl.imgPath.text = custL.getItemAt(0).col10;
	empl.phNumber.text = custL.getItemAt(0).col11;
	empl.email.text = custL.getItemAt(0).col3;
	empl.empStatus.text = custL.getItemAt(0).col2;
	empl.initFunction = onCreationComplete;
	PopUpManager.centerPopUp(empl);
	empl.setFocus();
}
